package com.bwie.controller;

import com.bwie.pojo.TbType;
import com.bwie.service.TbTypeService;
import com.bwie.utils.Result;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * description:
 *
 * @Author zhaohaoyang
 * @Create 2025/5/24 9:05
 * @Version 1.0
 */
@RestController
@RequestMapping("/shop/type")
public class TbTypeController {
    @Autowired
    TbTypeService tbTypeService;

    /**
     * 添加产品分类
     * @param tbType
     * @return
     */
    @PostMapping("/addType")
    public Result addType(@RequestBody TbType tbType){
        return tbTypeService.addType(tbType);
    }

    /**
     * 根据id删除分类
     * @param typeId
     * @return
     */
    @DeleteMapping("/deleteType/{typeId}")
    public Result deleteType(@PathVariable("typeId")Integer typeId){
        return tbTypeService.deleteType(typeId);
    }

    /**
     * 获取分类树
     * @return
     */
    @GetMapping("/getTypeTree")
    public Result getTypeTree(){
        return tbTypeService.getTypeTree();
    }

    /**
     * 修改状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/setTypeStatus/{id}/{status}")
    public Result setTypeStatus(@PathVariable("id")Integer id,@PathVariable("status")Integer status){
        return tbTypeService.setTypeStatus(id,status);

    }

    /**
     * 删除类型
     * @param typeId
     * @return
     */
    @PostMapping("/deleteTypeById/{typeId}")
    public Result deleteTypeById(@PathVariable("typeId")Integer typeId){
        return tbTypeService.deleteTypeById(typeId);
    }

    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    public Result uploadFile(@RequestPart("file")MultipartFile file){
        return tbTypeService.uploadFile(file);
    }

    /**
     * 编辑类型
     * @param tbType
     * @return
     */
    @PostMapping("/updateType")
    public Result updateType(@RequestBody TbType tbType){
        return tbTypeService.updateType(tbType);
    }

    /**
     * 获取分类树
     * @return
     */
    @PostMapping("/getTypeSelectTree")
    public Result getTypeSelectTree(){
        return tbTypeService.getTypeSelectTree();
    }


}
